/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef Program_h__
#define Program_h__

#include <d3d11.h>
#include <wrl/client.h>


namespace SkyEngine2d
{
	
	class Program
	{
	public:
		Program();
		~Program();
	
		template<typename VertexType>
		bool initWithByteArrays(ID3D11Device* device,const char * code_byte_arr, int byte_arr_size);
		void use(ID3D11DeviceContext * device_context);
		ID3D11InputLayout * getInputLayout() { return m_inputLayout.Get(); }
	private:
		enum
		{
			compile_type_vertex,compile_type_pixel
		};
	
		bool compileShader(ID3D11Device* device, const D3D11_INPUT_ELEMENT_DESC * input_element_desc,UINT num_element,const char * code_byte, int code_byte_size);
	private:
		Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
		Microsoft::WRL::ComPtr<ID3D11PixelShader>  m_pixelShader;
		Microsoft::WRL::ComPtr<ID3D11InputLayout>  m_inputLayout;
	
		static Program * sm_currentProgram;
	};
	
	template<typename VertexType>
	bool Program::initWithByteArrays(ID3D11Device* device,const char * code_byte_arr, int byte_arr_size)
	{
		compileShader(device, VertexType::InputElements, VertexType::InputElementCount, code_byte_arr, byte_arr_size);
		return true;
	}
}

#endif // Program_h__
